/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.tmd.controlefinanceiro.modelo;

import java.io.Serializable;
import java.util.Calendar;
import java.util.List;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author luis
 */
@Entity
@Table(name = "historico")
public class Historico implements Serializable{
    
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column
    private Integer id;
    
    @Temporal(TemporalType.DATE)
    private Calendar data;
    
    @Column 
    private Double SaldoAtual;
   
    @OneToOne(targetEntity = Cliente.class)
    @JoinColumn(columnDefinition = "id_cliente")
    private Cliente cliente;
    
    @OneToMany(targetEntity = Pagamento.class)
    @JoinColumn(columnDefinition = "id_pagamento")
    private List<Pagamento> pagamentos;
    
    @ManyToMany
    @JoinTable(name="historico_documento", 
        joinColumns={@JoinColumn(name="id_historico")}, 
        inverseJoinColumns={@JoinColumn(name="id_documento")})
    private List<Documento> documentos;

    public Historico() {
    }

    public Historico(Integer id, Calendar data, Double SaldoAtual, Cliente cliente, List<Pagamento> pagamentos, List<Documento> documentos) {
        this.id = id;
        this.data = data;
        this.SaldoAtual = SaldoAtual;
        this.cliente = cliente;
        this.pagamentos = pagamentos;
        this.documentos = documentos;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Calendar getData() {
        return data;
    }

    public void setData(Calendar data) {
        this.data = data;
    }

    public Double getSaldoAtual() {
        return SaldoAtual;
    }

    public void setSaldoAtual(Double SaldoAtual) {
        this.SaldoAtual = SaldoAtual;
    }

    public Cliente getCliente() {
        return cliente;
    }

    public void setCliente(Cliente cliente) {
        this.cliente = cliente;
    }

    public List<Pagamento> getPagamentos() {
        return pagamentos;
    }

    public void setPagamentos(List<Pagamento> pagamentos) {
        this.pagamentos = pagamentos;
    }

    public List<Documento> getDocumentos() {
        return documentos;
    }

    public void setDocumentos(List<Documento> documentos) {
        this.documentos = documentos;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 89 * hash + Objects.hashCode(this.id);
        hash = 89 * hash + Objects.hashCode(this.data);
        hash = 89 * hash + Objects.hashCode(this.SaldoAtual);
        hash = 89 * hash + Objects.hashCode(this.cliente);
        hash = 89 * hash + Objects.hashCode(this.pagamentos);
        hash = 89 * hash + Objects.hashCode(this.documentos);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Historico other = (Historico) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        if (!Objects.equals(this.data, other.data)) {
            return false;
        }
        if (!Objects.equals(this.SaldoAtual, other.SaldoAtual)) {
            return false;
        }
        if (!Objects.equals(this.cliente, other.cliente)) {
            return false;
        }
        if (!Objects.equals(this.pagamentos, other.pagamentos)) {
            return false;
        }
        if (!Objects.equals(this.documentos, other.documentos)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Historico{" + "id=" + id + ", data=" + data + ", SaldoAtual=" + SaldoAtual + '}';
    }

    public void setCliente() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
    
    
    
}
